Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce desktop app size #7744

Merged
merged 36 commits into from
Feb 25, 2022

Conversation

kidroca
Copy link
Contributor

@kidroca kidroca commented Feb 14, 2022

Details

electron-builder uses package.json to determine what node_modules needs to be packed inside the app (dependencies)
Our root package contains many dependencies irrelevant to desktop (e.g. ios/android stuff) an existing pattern dealing with this is to create a 2nd package.json only for Electron (native) dependencies: https://www.electron.build/tutorials/two-package-structure. So this is what we decided to do here.

The webpack configuration is updated so that we don't use a dist folder external to desktop
We're also using webpack to bundle main.js (config inspired by https://github.com/electron-react-boilerplate/electron-react-boilerplate).
It helps us by:

  • injecting .env to webpack and main.js
  • we don't have to keep the files list upto date each time we import something from ../src

Added some notes in desktop/README

Excluded package-lock changes to have less PR changes

  • ⚠️Todo: run npm install once this get reviewed

Fixed Issues

$ #6927

Tests

Run npm install before you start

  • Verify running locally npm run desktop still works (with/without .env file)
  • Verify the build scripts work to build local version. Running build-desktop and build-desktop-staging should not publish unless the --publish flag is used
  • Verify the build scripts would work in GH actions by trying them with the --publish flag.
    npm run build-desktop-staging -- --publish always

Since the webpack configs for web were modified we should check those as well

  • Verify npm run web still works
  • Verify npm run build builds the production web bundle
  • Verify npm run build-staging builds the staging web bundle

iOS and Android should be unaffected

QA Steps

For each env do the following:

Sample.check.desktop.app.sizes.mp4

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

image

Mobile Web

image

Desktop

DEV

image

STAGING

image

PROD

image

iOS

image

Android

image

@kidroca kidroca force-pushed the kidroca/feature/new-desktop-config branch 2 times, most recently from 3869c29 to 7a9c564 Compare February 14, 2022 18:09
@kidroca
Copy link
Contributor Author

kidroca commented Feb 14, 2022

Excluded package-lock changes to have less PR changes

  • Todo: run npm install once this get reviewed

@kidroca kidroca force-pushed the kidroca/feature/new-desktop-config branch from 7a9c564 to ff7da1b Compare February 14, 2022 18:23
Copy link
Contributor Author

@kidroca kidroca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added notes on some of the changes

config/webpack/webpack.common.js Show resolved Hide resolved
config/webpack/productionConfig.js Show resolved Hide resolved
Comment on lines 13 to 15
target: [
{target: 'dmg', arch: ['x64', 'arm64', 'universal']},
],
Copy link
Contributor Author

@kidroca kidroca Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop the universal target if we're not going to use it.
The idea is to give x64 to "old" mac users and arm64 for M1s
Universal works for both but is 2x the size (This was briefly touched on the issue as well: #6927 (comment))

BTW I have no problem running the x64 version on M1 - you can't really tell the difference

Sample build output for these targets:

image

config/electron.config.js Outdated Show resolved Hide resolved
config/electron.config.js Outdated Show resolved Hide resolved
@roryabraham roryabraham self-requested a review February 14, 2022 19:49
@roryabraham
Copy link
Contributor

I would like to review this once it's ready. A couple other suggestions that might be worth investigating to reduce bundle size:

@kidroca
Copy link
Contributor Author

kidroca commented Feb 15, 2022

A couple other suggestions that might be worth investigating to reduce bundle size:

App bundling enhancements would only reduce the app.js script size - 5.9Mb at the moment
Screenshot 2022-02-15 at 14 37 26

Even entirely removing app.js would only make App ~5Mb smaller, while the dmg would shrink by upto 1.5Mb

We would gain more by excluding source maps - 16.7Mb for app and 2.3Mb for pdf worker, though it would again make the installer just 5Mb smaller
(Source maps could be useful to someone debugging the prod app though)


This PR focuses on a lot bigger scale (not directly related to webpack bundling, but how electron-builder works)

  • getting installer from 326 down to 90Mb
  • installed size from 812 down to 210Mb

Babel enhancements are still worth for making the web app load faster (over internet), but don't bring much for the Desktop app

Default is `dist` and is used for temporary content while building
We also use `dist` to bundle the js script there
We should not use the same folder as in the end temp content (200MB) gets bundled in to the desktop app
Provide arguments through Webpack `env` CLI API

1. Have the base configuration setup for PROD
2. Have the dev configuration override it
3. Desktop use creates 2 configurations in parallel
@kidroca kidroca force-pushed the kidroca/feature/new-desktop-config branch from ff7da1b to 121a41a Compare February 15, 2022 20:50
This script is now getting bundled into `main.js` before `package.json` is modified by electron-builder
But the build process sets the `process.env.ELECTRON_ENV` so it's not a problem to just remove these lines

Note: updated return docs - the returned values are the lowercase names and not ['PROD', 'STG', 'DEV']
@kidroca kidroca force-pushed the kidroca/feature/new-desktop-config branch from 121a41a to b8cf68e Compare February 15, 2022 20:54
Copy link
Contributor Author

@kidroca kidroca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roryabraham
I've unified the 2 electron Builder configs and had to make changes to usages of ELECTRON_ENV. Particularly to ELECTRON_ENVIRONMENT.js I think it serves the same purpose this way.

Added a few more notes as code review comments

config/webpack/webpack.common.js Show resolved Hide resolved
config/webpack/webpack.desktop.js Outdated Show resolved Hide resolved
desktop/build.sh Outdated Show resolved Hide resolved
@kidroca kidroca marked this pull request as ready for review February 15, 2022 23:07
@kidroca kidroca requested a review from a team as a code owner February 15, 2022 23:07
@MelvinBot MelvinBot removed the request for review from a team February 15, 2022 23:07
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me. Just noticed a few things that could be improved in the readme.

desktop/README.md Outdated Show resolved Hide resolved
desktop/README.md Outdated Show resolved Hide resolved
desktop/README.md Outdated Show resolved Hide resolved
@kidroca
Copy link
Contributor Author

kidroca commented Feb 24, 2022

✔️ Ready for Review

Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Also, nice catch on renaming CONST/index.js.

@tgolen
Copy link
Contributor

tgolen commented Feb 24, 2022

conflicts :(

Copy link
Contributor

@roryabraham roryabraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and thanks for making all the revisions.

@kidroca
Copy link
Contributor Author

kidroca commented Feb 25, 2022

✔️ Conflict resolved
It was only due to CONST/index.js becoming CONST.js again and there was no conflict in merging the actual content. Even the approving reviews are still valid

@roryabraham roryabraham merged commit 3e674c4 into Expensify:main Feb 25, 2022
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@kidroca kidroca deleted the kidroca/feature/new-desktop-config branch February 28, 2022 09:59
@OSBotify
Copy link
Contributor

OSBotify commented Mar 1, 2022

🚀 Deployed to staging by @roryabraham in version: 1.1.41-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 failure ❌

@roryabraham
Copy link
Contributor

@kidroca I think this might have broken storybook builds: https://github.com/Expensify/App/runs/5380104817?check_suite_focus=true

I am able to reproduce the error on main by running npm run storybook-build

@kidroca
Copy link
Contributor Author

kidroca commented Mar 1, 2022

That's something I forgot to test, I'll try it and get back to you

@kidroca
Copy link
Contributor Author

kidroca commented Mar 1, 2022

Yes definitely broke storybook with the changes to webpack.common.js but can make it work again

@OSBotify
Copy link
Contributor

OSBotify commented Mar 2, 2022

🚀 Deployed to staging by @roryabraham in version: 1.1.41-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 failure ❌

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @francoisl in version: 1.1.41-6 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants